﻿using System;

class MaximalSum
{
    static void Main()
    {
        Console.Write("Enter the array length (N): ");

        int n = int.Parse(Console.ReadLine());

        Console.Write("Enter the number of elements (K) to be summarized (1 <= K <= N): ");

        int k = int.Parse(Console.ReadLine());

        int[] array = new int[n];

        Console.WriteLine();

        for (int i = 0; i < n; i++)
        {
            Console.Write("[{0}] = ", i);
            array[i] = int.Parse(Console.ReadLine());
        }

        Array.Sort(array);

        int maxSum = 0;

        Console.WriteLine();
        Console.WriteLine("The K elements forming maximal sum are:");

        for (int i = 0; i < k ; i++)
        {
            Console.WriteLine(array[array.Length - i - 1]);
            maxSum += array[array.Length - i - 1];
        }

        Console.WriteLine("The maximal sum is: " + maxSum);
    }
}
